<?php

namespace App\Http\Controllers\Home;

use App\Http\Requests\MessageRequest;
use App\Models\Message;
use Illuminate\Http\Request;

class MessageController extends CommonController
{

    /**
     * 权限验证
     * Create a new controller instance.
     *
     * MessageController constructor.
     */
    public function _initialize()
    {
        $this->middleware('auth');
    }

    /**
     * 留言板前台留言列表
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        //
    }

    /**
     * 留言板前台新增留言
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        return view('home.message.create', compact('new'));
    }

    /**
     * 留言板前台插入留言
     * Store a newly created resource in storage.
     *
     * @param MessageRequest $request
     * @return \Illuminate\Http\Response
     */
    public function store(MessageRequest $request)
    {
        $inputs = $request->except('_token', '_method');
        $inputs['u_id'] = $request->user()->id;
        $inputs['ip'] = $request->getClientIp();
        $result = Message::create($inputs);
        if($result){
            return redirect('/');
        } else {
            return redirect()->back()->withErrors(['error'=> '添加失败']);
        }
    }

    /**
     * 留言板前台查看留言
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * 留言板前台编辑留言
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * 留言板前台修改留言
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * 留言板前台删除留言
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
